
//boolean
let flag: boolean = true;
flag = false;
flag = null
flag = undefined
//number
let decLiteral: number = 6;
decLiteral = 7;
decLiteral = null
decLiteral = undefined
//string
let str: string = "bob";
str = "smith";
//数组
const list: number[] = [1, 2, 3];
list[4] = 5;


//数组泛型
const list2: Array<number> = [2];
list2[4] = 5;

//元组 Tuple

let x: [string, number];

x = ['hello', 45]

console.log(x);

//枚举
enum Color {
    Red, Green = 'hello', Blue = 'world'
}
let c: Color = Color.Green;
console.log(Color[0]);

//Any
let notSure: any = 4;
notSure = "maybe a string instead";
notSure = false;

//Void
function say(): void {
    console.log('hello world');
}
say();
//Null 和 Undefined
// Not much else we can assign to these variables!
let u: undefined = undefined;
let n: null = null;

//Never
function error(message: string): never {
    throw new Error(message);
}

// 返回never的函数必须存在无法达到的终点
function infiniteLoop(): never {
    while (true) {
    }
}
//Object


//类型断言
{
    let someValue: any = "this is a string";
    let strLength: number = (<string>someValue).length;
}
{
    let someValue: any = "this is a string";
    let strLength: number = (someValue as string).length;
}


